fix(idempotency): apply jmespath_options to payload_validation_jmespath - #8474
Conversation
The idempotency key search passes jmespath_options (by default the Powertools functions like powertools_json), but the payload validation search didn't pass any options. Any payload_validation_jmespath using powertools_json, powertools_base64, powertools_base64_gzip or a custom function raised "Unknown function" when hashing the payload, so every invocation failed with IdempotencyPersistenceLayerError before the handler ran. Pass the same options to the payload validation search.
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
leandrodamascena
left a comment
There was a problem hiding this comment.
Good catch, @Om-singhaI, and thanks for the fix! Both expressions should honor the same JMESPath options. I pushed a regression test covering overridden native functions, including the compatibility case where an unchanged payload is rejected because an older record’s hash was generated with the native function. All 135 idempotency tests pass locally.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8474 +/- ##
========================================
Coverage 96.80% 96.80%
========================================
Files 310 310
Lines 15541 15541
Branches 1354 1354
========================================
+ Hits 15044 15045 +1
Misses 361 361
+ Partials 136 135 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Issue number: closes #8473
Summary
Changes
BasePersistenceLayerpassesjmespath_optionsto the idempotency key search but not to thepayload_validation_jmespathsearch in_get_hashed_payload. By default those options hold the Powertools functions, sopowertools_json(),powertools_base64(),powertools_base64_gzip()and any custom function raisedUnknownFunctionErrorin the validation expression.save_inprogresshashes the payload before it writes the record. So every call failed withIdempotencyPersistenceLayerErrorand the handler never ran._get_hashed_payloadnow passes the samejmespath.Optionsas the key search.powertools_json(body)in both expressions. The same order replays the stored response, and a changed amount raisesIdempotencyValidationError.jmespath_optionsused inpayload_validation_jmespath.User experience
Before:
payload_validation_jmespath="powertools_json(body).amount"fails every call withUnknown function: powertools_json().After: the handler runs, and a repeat request with a changed amount raises
IdempotencyValidationError.Testing:
tests/functional/idempotency/_boto3/test_idempotency.pyfail on develop withUnknown functionerrors and pass here.tests/functional/idempotency/_boto3,tests/functional/idempotency/_pydanticandtests/unit/idempotency: 133 passed.ruff format --checkandruff checkpass on both files. mypy is clean onpersistence/base.py.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.